package com.eric.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenw-i
 * @version 1.0.0
 * @ClassName RabbitConfig.java
 * @Description TODO
 * @createTime 2020年07月29日 15:40:00
 */
@Configuration
public class RabbitTopicConfig {
    public static final String QUEUE_ORDER="QUEUE_ORDER";
    public static final String QUEUE_COMMON="QUEUE_COMMON";

    public static final String TOPIC_ORDER="TOPIC.ORDER";
    public static final String TOPIC_PRODUCT="TOPIC.PRODUCT";
    public static final String TOPIC_COMMON="TOPIC.#";

    public static final String TOPIC_EXCHANGE="CUSTOM_EXCHANGE";

    @Bean
    public Queue orderQueue() {
        return new Queue(QUEUE_ORDER);
    }

    @Bean
    public Queue commonQueue() {
        return new Queue(QUEUE_COMMON);
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    public Binding bindingExchangeOrder(Queue orderQueue, TopicExchange exchange) {
        return BindingBuilder.bind(orderQueue).to(exchange).with(TOPIC_ORDER);
    }

    @Bean
    public Binding bindingExchangeCommon(Queue commonQueue, TopicExchange exchange) {
        return BindingBuilder.bind(commonQueue).to(exchange).with(TOPIC_COMMON);
    }
}
